package co.yixiang.yshop.module.crm.api.workwx;

import co.yixiang.yshop.framework.common.util.object.BeanUtils;
import co.yixiang.yshop.module.crm.api.workwx.dto.WorkWxConfigDTO;
import co.yixiang.yshop.module.crm.api.workwx.dto.WorkWxUseDTO;
import co.yixiang.yshop.module.crm.dal.dataobject.crmworkwxconfig.CrmWorkWxConfigDO;
import co.yixiang.yshop.module.crm.dal.dataobject.crmworkwxuser.CrmWorkWxUserDO;
import co.yixiang.yshop.module.crm.dal.mysql.crmworkwxuser.CrmWorkWxUserMapper;
import co.yixiang.yshop.module.crm.service.crmworkwxconfig.CrmWorkWxConfigService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

/**
 * config API 实现类
 *
 * @author yshop
 */
@Service
public class ConfigApiImpl implements ConfigApi {

    @Resource
    private CrmWorkWxConfigService workWxConfigService;
    @Resource
    private CrmWorkWxUserMapper workWxUserMapper;

    @Override
    public WorkWxConfigDTO getConfig() {
        CrmWorkWxConfigDO workWxConfig = workWxConfigService.getWorkWxConfig(0);
        return BeanUtils.toBean(workWxConfig,WorkWxConfigDTO.class);
    }

    @Override
    public WorkWxUseDTO getWxUser(String userId) {
        CrmWorkWxUserDO workWxUserDO = workWxUserMapper.selectOne(new LambdaQueryWrapper<CrmWorkWxUserDO>()
                .eq(CrmWorkWxUserDO::getUserid,userId));
        return BeanUtils.toBean(workWxUserDO,WorkWxUseDTO.class);
    }

    @Override
    public void createWxUser(WorkWxUseDTO workWxUseDTO) {
        workWxUserMapper.insert(BeanUtils.toBean(workWxUseDTO,CrmWorkWxUserDO.class));
    }
}
